package lucene.server.cdc.mysql.util;

import lucene.server.common.utils.StringUtil;

public class SqlParser {
    public static String getTableName(String sql)
    {
        //`food-supervision`.`jjhk`
        return "";
    }
    /**
     * 判断数据库是否在filter里面
     * */
    public static boolean isInFilter(String dbName,String[] filters)
    {
        if (StringUtil.isEmpty(dbName)){
            return false;
        }
        if (filters==null || filters.length == 0 || filters[0].equals("*")){
            return true;
        }
        for (String filterStr : filters){
            if (filterStr.toLowerCase().equals(dbName.toLowerCase())){
                return true;
            }
        }
        return false;
    }
    /**
     * 判断sql语句是否针对表进行操作
     * */
    public static boolean isCheckDDL(String sql,String type)
    {
        if (StringUtil.isEmpty(sql) || StringUtil.isEmpty(type)){
            return false;
        }
        type = type.toLowerCase()+"table";
        return sql.replace(" ","").toLowerCase().startsWith(type);
    }
}
